package com.apkcore.core.ext

import com.apkcore.core.util.HexUtil
import java.nio.charset.Charset
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

fun String.toAddress(): String {
    return HexUtil.toAddress(this)
}

fun String.reverseText(chunkSize: Int = 2): String {
    return HexUtil.reverseText(this, chunkSize)
}

fun ByteArray?.bytes2Hex(): String {
    return HexUtil.bytes2Hex(this)
}

fun ByteArray?.bytes2Text(charset: Charset = Charsets.UTF_8): String {
    return HexUtil.bytes2Text(this, charset)
}

fun String.hex2Bytes(): ByteArray {
    return HexUtil.hex2Bytes(this)
}

fun Long.toTimestamp(pattern: String = "yyyy-MM-dd HH:mm:ss"): String {
    val sdf = SimpleDateFormat(pattern, Locale.getDefault())
    val date = Date(this)
    return sdf.format(date)
}